package com.zlt.bkparking.controller.parking;


import com.github.pagehelper.PageInfo;
import com.zlt.bkparking.dto.FeedBackDTO;
import com.zlt.bkparking.service.FeedBackService;
import com.zlt.bkparking.vo.FeedbackVO;
import com.zlt.bkparking.vo.ParkingVo;
import com.zlt.bkparking.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@RequestMapping("feedback")
@RestController
@Slf4j
public class FeedBackController {

    @Autowired
    private FeedBackService feedbackService;



    @PostMapping("feedback")
    public Result selectFeedBack(FeedBackDTO feedBackDTO){
        try {
            PageInfo<FeedbackVO> feedbackVOS = feedbackService.selectFeed(feedBackDTO);
            return Result.ok("查询成功",feedbackVOS);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("查询失败："+e.getMessage());
        }
    }

    @GetMapping("Unread")
    public Result Unread(FeedBackDTO feedBackDTO){
        try {
            PageInfo<FeedbackVO> feedbackVOS = feedbackService.selectUnread(feedBackDTO);
            return Result.ok("查询成功",feedbackVOS);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("查询失败："+e.getMessage());
        }
    }

    @GetMapping("Read")
    public Result Read(FeedBackDTO feedBackDTO){;
        try {
            PageInfo<FeedbackVO> feedbackVOS = feedbackService.selectRead(feedBackDTO);
            return Result.ok("查询成功",feedbackVOS);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("查询失败："+e.getMessage());
        }
    }
    /**
     * 通过停车场id筛选反馈信息
     * @param feedBackDTO
     * @return
     */
    @PostMapping("feedbackbyplId")
    public Result selectFeedBackByplId(FeedBackDTO feedBackDTO){
        try {
            PageInfo<FeedbackVO> feedbackVOS = feedbackService.selectFeedBackByplId(feedBackDTO);
            return Result.ok("查询成功",feedbackVOS);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("查询失败："+e.getMessage());
        }
    }

    /**
     * 通过用户id筛选反馈信息
     * @param feedBackDTO
     * @return
     */
    @PostMapping("feedbackbyauId")
    public Result selectFeedBackByauId(FeedBackDTO feedBackDTO){
        try {
            PageInfo<FeedbackVO> feedbackVOS = feedbackService.selectFeedBackByauId(feedBackDTO);
            return Result.ok("查询成功",feedbackVOS);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("查询失败："+e.getMessage());
        }
    }

    /**
     * 通过时间筛选反馈信息
     * @param feedBackDTO
     * @return
     */
    @PostMapping("feedbackbyfbTime")
    public Result feedbackByfbTime(FeedBackDTO feedBackDTO){
        try {
            PageInfo<FeedbackVO> feedbackVOS = feedbackService.selectFeedBackByfbTime(feedBackDTO);
            return Result.ok("查询成功",feedbackVOS);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("查询失败："+e.getMessage());
        }
    }

    /**
     * 修改已读未读
     * @param feedBackDTO
     * @return
     */
    @PostMapping("updatestate")
    public Result updatestate(FeedBackDTO feedBackDTO){
        try {
            boolean updatestate = feedbackService.updatestate(feedBackDTO);
            return updatestate ? Result.ok("修改成功") : Result.error("修改失败") ;
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("修改失败："+e.getMessage());
        }
    }


    /**
     * 删除反馈
     * @param feedBackDTO
     * @return
     */
    @PostMapping("delfeedback")
    public Result delfeedback(FeedBackDTO feedBackDTO){
        try {
            Long fbId = feedBackDTO.getFbId();
            boolean delfeedback = feedbackService.delfeedback(fbId);
            return Result.ok("删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("修改失败："+e.getMessage());
        }
    }
}
